/* ---------------------------------Marlin Toolkit-----------------------------*
Authors : Daniel Randle, Alex Bourne
Date Created : Feb 20 2013

File:
	logfile.h

Description:
	This file contains the declaration for the logfile class along with any
	helper functions associated with the class
*-----------------------------------------------------------------------------*/

#ifndef LOGFILE_H
#define LOGFILE_H

// Inlcudes
#include <qstring.h>
#include <sstream>
#include <string>

// Class Forward Declarations
class QFile;
class QTextStream;

/*------------------------------Class LogFile----------------------------------*
Description:
	This class is in charge of printing output to logfiles as specified with
	the implementation. You can create a LogFile object specifying the name
	of the log file only - this will search for the file in the working
	directory and open it in append mode if it exists, and if not it will create
	a new text file with the name specified and write to it. If no name is
	specified then it will write to "log.txt" by default.
*-----------------------------------------------------------------------------*/
class LogFile
{
public:
	enum WriteMode {APPEND,OVERWRITE};

	// Ctors
	LogFile(const std::string & text="", const QString & fileName="enginedebug.log", const QString & directory="Logs");
	LogFile(const std::stringstream & stream, const QString & fileName="enginedebug.log", const QString & directory="Logs");

	// Dtor
	~LogFile();

	// set
	void setFileName(const QString & fileName);
	void setDirectory(const QString & directory);
	void setWriteMode(WriteMode mode);
	void setTimeStampEnabled(bool);

	// get
	const QString & getFileName() const;
	const QString & getDirectory() const;
	WriteMode getWriteMode() const;
	bool isTimeStampEnabled() const;

	// functionality
	bool write(const QString & text);
	bool write(const char * c_str);
	bool write(const std::string & str);
	bool write(const std::stringstream & num);
	bool write(float num);
	bool write(int num);

	bool writeDate();

	// Static methods
	static bool writeDate(const QString & fname,WriteMode mode = OVERWRITE);
	static bool writeToCom(const QString & text,WriteMode mode = APPEND);
	static bool writeTo(const QString & text, const QString &fname, WriteMode = APPEND);

private:
	WriteMode currentWriteMode;
	QString filename;
	QString dir;
	bool timeStampEnabled;
};

#endif  // LOGFILE_H